#!/usr/bin/env bash

# Filename     :	kubectl-cmd-install.sh
# Last modified:	2022-09-27 12:12
# Version      :
# Author       : jack.zang
# Email        : jack.zang@aishangwei.net
# Description  :
# 使用方法：source <(curl -sL https://gitee.com/jack_zang/public-scripts/raw/master/shell/kubernetes/kubectl/kubectl-cmd-install.sh)
# ******************************************************


read -t 30 -p "请输入要安装的 kubectl 版本，例：v1.24.6 ,直接回车安装默认版本 v1.24.6：" KUBECTL

[ -z "$KUBECTL" ] && KUBECTL="v1.24.6"

curl -Lo /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/"${KUBECTL}"/bin/linux/amd64/kubectl
# 校验文件
curl -Lo /tmp/kubectl.sha256 "https://dl.k8s.io/"${KUBECTL}"/bin/linux/amd64/kubectl.sha256"
echo "$(cat /tmp/kubectl.sha256) /usr/local/bin/kubectl" | sha256sum --check
if [ $? != 0 ] ; then
  echo " kubectl 文件校验失败，请重新检查安装"
  exit 1
fi

chmod +x /usr/local/bin/kubectl

echo "----------- kubectl 版本 ----------"
kubectl version -o json
